package com.xiguanlezz.cn.server;

import com.xiguanlezz.cn.scanner.RpcServiceScanner;

import java.net.InetSocketAddress;
import java.util.Map;
import java.util.Objects;

/**
 * @Author：习惯了种种
 * @CreateDate：2024/11/3 14:49
 * @Description：
 */
public class RpcSingleServer {
    private NettyServer nettyServer;
    private Map<String, Object> handlerMap;

    public RpcSingleServer(InetSocketAddress address, String scanPackage) {
        nettyServer = new NettyServer(address);
        this.handlerMap = RpcServiceScanner.doScanAndRegisterService(scanPackage);
    }

    public RpcSingleServer(InetSocketAddress address, String reflectTYpe, String scanPackage) {
        nettyServer = new NettyServer(address, reflectTYpe);
        this.handlerMap = RpcServiceScanner.doScanAndRegisterService(scanPackage);
    }

    public void start() {
        if (Objects.nonNull(nettyServer)) {
            nettyServer.setHandlerMap(handlerMap);
            nettyServer.startServer();
        }
    }
}
